<%-- 
    Document   : delGoods
    Created on : Oct 28, 2011, 4:36:03 AM
    Author     : Admin
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categoryBean.Category"%>
<%@page import="categoryBean.CategoryHome"%>
<%@page import="goodsBean.Goods"%>
<%@page import="goodsBean.GoodsHome"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.HashMap"%>
<%@page import="DBConnection.ATeamObject"%>
<%@ page errorPage = "Error.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Удаление товара</title>
        <%  InitialContext initialContext;
            GoodsHome goodsHome;
            Goods goods;     
            Object homeObject;
            
            CategoryHome categoryHome;
            Category category;
            Object homeObject1;
            
            Manufacturer manufacturer;
            ManufacturerHome manufacturerHome;
            Object homeObject2;
            
            ATeamObject ato = new ATeamObject();
            
            initialContext = new InitialContext();
            homeObject = initialContext.lookup("GoodsBean");
            goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                    GoodsHome.class);

            homeObject1 = initialContext.lookup("CategoryBean");
            categoryHome = (CategoryHome) PortableRemoteObject.narrow(homeObject1,
                    CategoryHome.class);

            homeObject2 = initialContext.lookup("ManufacturerBean");
            manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(homeObject2,
                    ManufacturerHome.class);
        %>
    </head>
    <body background="1.jpg" bgproperties="fixed">
        <h4><a href="index.jsp">Главная</a></h4> 
        <a href="delGoods.jsp">Удаление товара</a>
        <h1>Удаление товара</h1>
        <%  if (!request.getParameterMap().isEmpty()){
                goods = goodsHome.findByPrimaryKey(Integer.parseInt(request.getParameter("name")));
                goods.remove();
                response.sendRedirect("index.jsp");
            }
            else{
        %>
        <form name="delGoods" action="delGoods.jsp">
            <p> Название товара
                <select name="name">
                <%  Collection allGoods = goodsHome.findAllGoods();
                    Iterator iter = allGoods.iterator(); 
                    while(iter.hasNext()){
                        goods = (Goods)iter.next();
                %>
                        <option value="<%= goods.getGoodsId() %>"><%= goods.getNameOfGoods() %></option>
                <%
                    }
                %>
                </select>
            </p>
            <p>
                <input type="submit" value="Удалить" name="delete" />
            </p>
        </form>
        <%
            };
        %>  
    </body>
</html>
